package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie01.do")
public class Cookie01Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.创建Cookie对象
        Cookie cookie01 = new Cookie("cookie01", "value01");
        //2.通知客户端保存Cookie
        response.addCookie(cookie01);
        //1.创建Cookie对象
        Cookie cookie02 = new Cookie("cookie02", "value01");
        //2.通知客户端保存Cookie
        response.addCookie(cookie02);        //1.创建Cookie对象
        Cookie cookie03 = new Cookie("cookie03", "value01");
        //2.通知客户端保存Cookie
        response.addCookie(cookie03);
        Cookie cookie04 = new Cookie("cookie04", "value04");
        cookie04.setPath(request.getContextPath() + "/admin");
        //2.通知客户端保存Cookie
        response.addCookie(cookie04);
        Cookie cookie05 = new Cookie("cookie05", "value01");
        //2.通知客户端保存Cookie
        //request.getContextPath() 获取工程路径
        cookie05.setPath(request.getContextPath() + "/user");
        response.addCookie(cookie05);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
